import urllib.request
import re


def crawler():
    linklist = []
    thistitle =[]
    headers = {'User-Agent':'ozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Mobile Safari/537.36'}
    url = "http://blog.csdn.net/kXYOnA63Ag9zqtXx0/article/details/79050518"
    req = urllib.request.Request(url=url,headers=headers)
    thishtml = urllib.request.urlopen(req).read().decode('utf-8')
    print(thishtml)
#使用req打开后网页源码
    
#    files = urllib.request.urlopen(url).read().decode('utf-8')
#    print(file)
#直接使用url打开网页源码



#    pat2 = ' <h1 class="csdn_top">(.*?)</h1>'
#    pat3 = '<h3 class="article_t">(.*?)</h3>'
#    thistitle = re.compile(pat3).findall(thishtml)
#    print(len(thistitle))
 # file = urllib.request.urlretrieve(url,'C:/Users/Administrator/Desktop/pythoncode/web'+'/'+thistitle[0]+'.html')
 #   with open('C:/Users/Administrator/Desktop/pythoncode/web'+'/'+thistitle[0]+'123'+'.html','w',encoding='utf-8') as file:
 #       file.write(files)

#path = str(input("请输入网页存储文件夹："))
crawler()
